package me.shiqiang.im;

import com.aliyun.openservices.ons.api.bean.ProducerBean;
import me.shiqiang.im.config.RocketMqProducerConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;

import javax.servlet.MultipartConfigElement;

//@SpringCloudApplication
@EnableRedisRepositories
@EnableFeignClients
@EnableCaching
@SpringBootApplication
public class ImHttpServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(ImHttpServerApplication.class, args);
	}

	@Bean(name="event", initMethod = "start", destroyMethod = "shutdown")
	public ProducerBean createProducerBean(RocketMqProducerConfig config) {
		ProducerBean producerBean = new ProducerBean();
		producerBean.setProperties(config.getProperties());
		return producerBean;
	}

	@Bean(name = "sender", initMethod = "start", destroyMethod = "shutdown")
	public ProducerBean createMsgSenderProducerBean(RocketMqProducerConfig config) {
		ProducerBean producerBean = new ProducerBean();
		producerBean.setProperties(config.getProperties());
		return producerBean;
	}


	@Bean
	public SnowFlake createSnowFlake() {
		return new SnowFlake(SnowFlake.MACHINE_MAX_NUM);
	}


//	@Bean
//	public MultipartConfigElement multipartConfigElement() {
//		MultipartConfigFactory factory = new MultipartConfigFactory();
//		//  单个数据大小
//		factory.setMaxFileSize("1024KB");
//		/// 总上传数据大小
//		factory.setMaxRequestSize("5000KB"); //200k * (24+1)
//		return factory.createMultipartConfig();
//	}


}
